import 'package:flutterapp2/util/safe_parse.dart';

class TestSafeParseBean {
	num data;
	String name;
	num id;
	List<num> list;
	// 定义的是对下，后端返回的是list的兼容测试，会返回null
	ParamsBean params;

	TestSafeParseBean({this.data, this.name, this.id, this.list, this.params});

	TestSafeParseBean.fromJson(Map<String, dynamic> json) {
		data = safeParse(json, 'data', 'num');
		name = safeParse(json, 'name', 'String');
		id = safeParse(json, 'id', 'num');
		list = safeParse(json, 'list', 'List<dynamic>')?.cast<num>();
		params = safeParse(json, 'params') != null ? ParamsBean.fromJson(safeParse(json, 'params')) : null;
	}

	Map<String, dynamic> toJson() {
		final Map<String, dynamic> data = Map<String, dynamic>();
		data['data'] = this.data;
		data['name'] = this.name;
		data['id'] = this.id;
		data['list'] = this.list;
		if (this.params != null) data['params'] = this.params.toJson();
		return data;
	}
}

class ParamsBean {
	String key1;
	String key2;
	String key3;

	ParamsBean({this.key1, this.key2, this.key3});

	ParamsBean.fromJson(Map<String, dynamic> json) {
		key1 = safeParse(json, 'key1', 'String');
		key2 = safeParse(json, 'key2', 'String');
		key3 = safeParse(json, 'key3', 'String');
	}

	Map<String, dynamic> toJson() {
		final Map<String, dynamic> data = Map<String, dynamic>();
		data['key1'] = this.key1;
		data['key2'] = this.key2;
		data['key3'] = this.key3;
		return data;
	}
}
